package com.yc.c118s3plyqnzf.util;

import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;

public class LocalDateConvertor implements Converter<String, LocalDate> {
    @Override
    public LocalDate convert(String s) {
        System.out.println("------------------------------" + s);
        // yyyy年MM月dd日 => yyyy-MM-dd
        if (s.matches("\\d{4}\\D+\\d{2}\\D+\\d{2}\\D*")){
            String string = s.replaceAll("(\\d{4})\\D+(\\d{2})\\D+(\\d{2})\\D*",
                    "$1-$2-$3");
            return LocalDate.parse(string);
        }
        throw new RuntimeException("日期格式错误！");
    }
}
